package com.shopping.control;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.shopping.dao.impl.BizDaoImpl;
import com.shopping.entity.TbAffiche;
import com.shopping.entity.TbBigType;
import com.shopping.entity.TbGoods;
import com.shopping.entity.TbLink;
import com.shopping.entity.TbMember;
import com.shopping.service.impl.BizServiceImpl;

/**
 * Servlet implementation class ServletInit
 */
public class ServletInit extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletInit() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see Servlet#init(ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
    }

    /**
     * @see Servlet#destroy()
     */
    public void destroy() {
        // TODO Auto-generated method stub
        super.destroy();
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {
        // TODO Auto-generated method stub
        BizDaoImpl bdi = new BizDaoImpl();
        BizServiceImpl bsi = new BizServiceImpl();
        bsi.setBizdao(bdi);// 注入

        List<TbBigType> list = bsi.getBigName();// 查询产品类别
        List<TbMember> listmember = bsi.getAllMember();// 查询用户
        List<TbGoods> numgoods = bsi.getGoods();// 按number降序查询
        List<TbGoods> listgoods = bsi.getAllGoods();// 查询所有的非特价并有库存的商品；
        List<TbGoods> freegoods = bsi.getFreeGoods();// 查询所有特价商品
        List<TbAffiche> listaffiche = bsi.getAllTitle();// 获取公告标题
        List<TbLink> listlink = bsi.getAllTink();// 获取链接
        HttpSession session = request.getSession();

        session.setAttribute("uesr", null); // 初始判断登陆键值对
        session.setAttribute("add", null); // 初始注册成功界面隐藏fg-four
        session.removeAttribute("TB"); // 删除缓存——会员修改

        session.setAttribute("listmember", listmember);// 用户集合清单
        session.setAttribute("list", list);// 产品类型集合
        session.setAttribute("numgoods", numgoods);// 销售产品集合
        session.setAttribute("listgoods", listgoods);//
        session.setAttribute("freegoods", freegoods);
        session.setAttribute("listaffiche", listaffiche);
        session.setAttribute("listlink", listlink);
        request.getRequestDispatcher("index.jsp").forward(request, response);
        // System.out.println(listmember);

    }

}
